package com.rerun.phone.park;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.rerun.common.bean.Rest;
import com.rerun.common.controller.SuperController;
import com.rerun.entity.WatchedResume;
import com.rerun.service.ICollectionResumeService;
import com.rerun.service.IWatchedJobService;
import com.rerun.service.IWatchedResumeService;
import com.rerun.vo.park.ParkResumeViewVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(value="园长端-互动",description="园长端-互动")
@RestController
@RequestMapping(value = "/parkApi/interact")
public class ParkInteractController extends SuperController{
	@Autowired
	private IWatchedResumeService watchedResumeService;
	@Autowired
	private ICollectionResumeService collectionResumeService;
	@Autowired
	private IWatchedJobService watchedJobService;
	
	@ApiOperation(value = "看过我", httpMethod = "GET",notes = "看过我")
	@RequestMapping(value = "/look/{parkId}/{pageNumber}",method=RequestMethod.GET)
	public Rest look(@PathVariable String parkId,@PathVariable int pageNumber) {
		Page<ParkResumeViewVo> page = getPage(pageNumber);
		try {
			page = watchedJobService.selectParkWatchListPage(page,parkId);
			return Rest.okData(page.getRecords());
		} catch (Exception e) {
			e.printStackTrace();
			return Rest.failure("error");
		}
	}
	
	@ApiOperation(value = "对我感兴趣", httpMethod = "GET",notes = "对我感兴趣")
	@RequestMapping(value = "/interest/{parkId}/{pageNumber}",method=RequestMethod.GET)
	public Rest interest(@PathVariable String parkId,@PathVariable int pageNumber) {
		Page<ParkResumeViewVo> page = getPage(pageNumber);
		try {
			page = collectionResumeService.selectCollectionWatchListPage(page,parkId);
			return Rest.okData(page.getRecords());
		} catch (Exception e) {
			e.printStackTrace();
			return Rest.failure("error");
		}
	}
	@ApiOperation(value = "添加看过简历", httpMethod = "GET",notes = "添加看过简历")
	@RequestMapping(value = "/addLook/{parkId}/{memberId}",method=RequestMethod.GET)
	public Rest addLook(@PathVariable long parkId,@PathVariable String memberId) {
		try {
			EntityWrapper<WatchedResume> entityWrapper = new EntityWrapper<>();
			entityWrapper.eq("parkId", parkId);
			entityWrapper.eq("memberId", memberId);
			List<WatchedResume> resumes = watchedResumeService.selectList(entityWrapper);
			if(resumes != null && resumes.size() > 0) {
				WatchedResume watchedResume = resumes.get(0);
				watchedResume.setCreateTime(new Date());
				watchedResumeService.updateAllColumnById(watchedResume);
			}else {
				WatchedResume arg0 = new WatchedResume();
				arg0.setCreateTime(new Date());
				arg0.setMemberId(memberId);
				arg0.setParkId(parkId);
				watchedResumeService.insert(arg0);
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return Rest.failure("添加失败");
		}
		return Rest.ok();
	}
}
